package servlet;

import util.JDBCUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/UpdateEmployeeServlet")
public class UpdateEmployeeServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取新增页面addEmployee.html传过来的值；
        int employeeId= Integer.parseInt(req.getParameter("employeeId"));
        String employeeName=req.getParameter("employeeName");
        String username=req.getParameter("username");

        String email=req.getParameter("email");
        String phone=req.getParameter("phone");
        List params=new ArrayList();
        //定义sql语句和参数变量列表
        String sql="UPDATE employee set employeename=?,username=?,email=?,phone=? where employeeid=?";
        params.add(employeeName);params.add(username);
        params.add(email);params.add(phone);params.add(employeeId);
        //执行更新
        JDBCUtil.execStatement(sql,params);
        //跳转到ListEmployeeServer
        resp.sendRedirect("ListEmployeeServlet");

    }
}
